#include "aspect.h"
using namespace sge;

#include <cstdarg>

Aspect::Aspect(const String& _name, const String& _type, const String& _family, Object* _object) :
    name(_name),
    type(_type),
    family(_family),
    object(_object),
    initialized(false),
    active(true),
    destroyed(false) {
}

bool Aspect::preInit() {
    if (!initialized && !destroyed) {
        init();
        initialized = true;
        return true;
    } else
        return false;
}

bool Aspect::preUpdate(float time, float dtime) {
    if (initialized && active && !destroyed) {
        update(time, dtime);
        return true;
    } else
        return false;
}

bool Aspect::preDestroy() {
    if (initialized && !destroyed) {
        destroy();
        destroyed = true;
        return true;
    } else
        return false;
}

bool Aspect::getActive() const {
    return active;
}

void Aspect::setActive(bool _active) {
    active = _active;
}

void Aspect::log(const char* format, ...) {
    char buffer[1024];
    va_list ap;
    va_start(ap,format);
    vsprintf(buffer,format,ap);
    
    object->log("%s: %s",name.c_str(),buffer);
}
